package com.zengqingfa.juc.demo2;

/**
 * @fileName: ThreadWaitAndNotify
 * @author: zengqf3
 * @date: 2021-7-20 8:38
 * @description:
 */
public class ThreadWaitAndNotify {

    public static Object monitor = new Object();

    public static void main(String[] args) throws Exception{
        Thread A = new Thread(() -> {
            synchronized (monitor) {
                System.out.println(Thread.currentThread().getName() + "线程");
                try {
                    monitor.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "A");

        Thread B = new Thread(() -> {
            synchronized (monitor) {
                monitor.notifyAll();
                System.out.println(Thread.currentThread().getName() + "线程");
            }
        }, "B");
        A.start();
        B.start();
    }
}
